<?php

namespace App\Transformers;

use App\Models\Order;

class OrderTransformer extends BaseTransformer
{
    protected $availableIncludes = ['goods'];

    public function transform(Order $model)
    {
        $data = [
            'id' => $model->id,
            'no' => $model->no,                                     #订单编号
//            'shop_id' => $model->shop_id,                           #用户id
            'image' => image_url($model->goods->image),                           #用户id
            'user_avatar' => image_url($model->user->avatar),       #預約人頭像
            'contact_name' => $model->contact_name,                 #联系人
            'contact_phone' => $model->contact_phone,               #联系人电话
            'scheduled_begin_time' => date_format(date_create($model->schedule->begin_time), 'Y-m-d H:i'),#预定时间
            'scheduled_end_time' => date_format(date_create($model->schedule->begin_time), 'Y-m-d H:i'),
            'total_amount' => $model->total_amount,                 #支付金额
            'paid_at' => $model->paid_at,                           #支付时间
            'refund_status' => $model->refund_status,               #退款状态
            'refund_verify' => $model->refund_verify,               #退款验证是否成功
            'refund_at' => $model->refund_at,                       #退款时间
            'status' => $model->status,                             #订单状态
            'closed' => $model->closed,                             #订单是否关闭
            'user_distance' => $model->user_distance,               #用户距离订单约定地点距离
            'remark' => $model->remark,                             #备注
            //'goods_id' => $model->goods_id,                       #商品id
            //'goods_type' => $model->goods_type,                   #商品类型
            'title' => $model->goods->title,                        #标题
            'shop_name' => $model->goods->shop->name,               #商店名称
            'created_at' => $model->created_at->toDateTimeString(), #创建时间
        ];

        return $this->_select($data);

    }

    public function includeGoods(Order $model)
    {
        return $this->item($model->goods, new ProductTransformer());
    }
}
